<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>范例</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="chdb.constants.html">预定义常量</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.chdb.html">chdb</a></div>
 <div class="up"><a href="book.chdb.html">chdb</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="chdb.examples" class="chapter">
 <h1>范例</h1>

 <div class="example" id="example-4113">
  <p><strong>Example #1 Creating a chdb file</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$data&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'key1'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'value1'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'key2'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'value2'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;...<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">chdb_create</span><span style="color: #007700">(</span><span style="color: #DD0000">'data.chdb'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>
   The above example will generate a chdb file named
   <em>data.chdb</em> and containing the key-value pairs defined in
   <var class="varname"><var class="varname">$data</var></var>.
  </p></div>
 </div>
 <div class="example" id="example-4114">
  <p><strong>Example #2 Loading and looking up a chdb file</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$chdb&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">chdb</span><span style="color: #007700">(</span><span style="color: #DD0000">'data.chdb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$value1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$chdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'key1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$value2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$chdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'key2'</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$value1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$value2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
value1
value2
</pre></div>
  </div>
 </div>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="chdb.constants.html">预定义常量</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.chdb.html">chdb</a></div>
 <div class="up"><a href="book.chdb.html">chdb</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
